#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>

int GetNumberOfK(int *data, int dataLen, int k) {
    int count = 0;
    int left = 0;
    int right = dataLen - 1;
    int mid = 0;
    while (left <= right) {
        mid = (left + right) / 2;
        if (data[mid] == k) {
            count++;
            break;
        } else if (data[mid] < k) {
            left = mid + 1;
        } else if (data[mid] > k) {
            right = mid - 1;
        }
    }

    if (count == 0|| dataLen == 0) {
        return 0;
    }
    for (int i = 1; i <= dataLen; i++) {
        if(data[mid - i] == k) {
            count++;
        }
        if (data[mid + i] == k) {
            count++;
        }
    }
    return count;
}

int main() {
    int arr[6] = {1,3,3,3,4,5};
    printf("%d", GetNumberOfK(arr, 6, 2));
    return 0;
}